package com.ruoyi.pingan.fymodule.sxosafetyaccountrecord.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.pingan.fymodule.sxosafetyaccountrecord.entity.SxoSafetyAccountRecord;
import com.ruoyi.pingan.fymodule.sxosafetyaccountrecord.param.SxoSafetyAccountRecordAddParam;
import com.ruoyi.pingan.fymodule.sxosafetyaccountrecord.param.SxoSafetyAccountRecordEditParam;
import com.ruoyi.pingan.fymodule.sxosafetyaccountrecord.param.SxoSafetyAccountRecordIdParam;
import com.ruoyi.pingan.fymodule.sxosafetyaccountrecord.param.SxoSafetyAccountRecordPageParam;
import com.ruoyi.pingan.fymodule.sxosafetyaccountrecord.service.SxoSafetyAccountRecordService;
import com.ruoyi.pingan.annotation.CommonLog;
import com.ruoyi.pingan.fymodule.thirdpa.util.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;



import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 分账账户日志控制器
 *
 * @author songlc
 * @date  2025/09/16 08:54
 */
@Tag(name = "分账账户日志控制器")
@RestController
@Validated
public class SxoSafetyAccountRecordController {

    @Resource
    private SxoSafetyAccountRecordService sxoSafetyAccountRecordService;

    /**
     * 获取分账账户日志分页
     *
     * @author songlc
     * @date  2025/09/16 08:54
     */
    @Operation(summary = "获取分账账户日志分页")
    @SaCheckPermission("/biz/sxosafetyaccountrecord/page")
    @GetMapping("/biz/sxosafetyaccountrecord/page")
    public CommonResult<Page<SxoSafetyAccountRecord>> page(SxoSafetyAccountRecordPageParam sxoSafetyAccountRecordPageParam) {
        return CommonResult.data(sxoSafetyAccountRecordService.page(sxoSafetyAccountRecordPageParam));
    }

    /**
     * 添加分账账户日志
     *
     * @author songlc
     * @date  2025/09/16 08:54
     */
    @Operation(summary = "添加分账账户日志")
    @CommonLog("添加分账账户日志")
    @SaCheckPermission("/biz/sxosafetyaccountrecord/add")
    @PostMapping("/biz/sxosafetyaccountrecord/add")
    public CommonResult<String> add(@RequestBody @Valid SxoSafetyAccountRecordAddParam sxoSafetyAccountRecordAddParam) {
        sxoSafetyAccountRecordService.add(sxoSafetyAccountRecordAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑分账账户日志
     *
     * @author songlc
     * @date  2025/09/16 08:54
     */
    @Operation(summary = "编辑分账账户日志")
    @CommonLog("编辑分账账户日志")
    @SaCheckPermission("/biz/sxosafetyaccountrecord/edit")
    @PostMapping("/biz/sxosafetyaccountrecord/edit")
    public CommonResult<String> edit(@RequestBody @Valid SxoSafetyAccountRecordEditParam sxoSafetyAccountRecordEditParam) {
        sxoSafetyAccountRecordService.edit(sxoSafetyAccountRecordEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除分账账户日志
     *
     * @author songlc
     * @date  2025/09/16 08:54
     */
    @Operation(summary = "删除分账账户日志")
    @CommonLog("删除分账账户日志")
    @SaCheckPermission("/biz/sxosafetyaccountrecord/delete")
    @PostMapping("/biz/sxosafetyaccountrecord/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SxoSafetyAccountRecordIdParam> sxoSafetyAccountRecordIdParamList) {
        sxoSafetyAccountRecordService.delete(sxoSafetyAccountRecordIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取分账账户日志详情
     *
     * @author songlc
     * @date  2025/09/16 08:54
     */
    @Operation(summary = "获取分账账户日志详情")
    @SaCheckPermission("/biz/sxosafetyaccountrecord/detail")
    @GetMapping("/biz/sxosafetyaccountrecord/detail")
    public CommonResult<SxoSafetyAccountRecord> detail(@Valid SxoSafetyAccountRecordIdParam sxoSafetyAccountRecordIdParam) {
        return CommonResult.data(sxoSafetyAccountRecordService.detail(sxoSafetyAccountRecordIdParam));
    }

    /**
     * 下载分账账户日志导入模板
     *
     * @author songlc
     * @date  2025/09/16 08:54
     */
    @Operation(summary = "下载分账账户日志导入模板")
    @GetMapping(value = "/biz/sxosafetyaccountrecord/downloadImportTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void downloadImportTemplate(HttpServletResponse response) throws IOException {
        sxoSafetyAccountRecordService.downloadImportTemplate(response);
    }

    /**
     * 导入分账账户日志
     *
     * @author songlc
     * @date  2025/09/16 08:54
     */
    @Operation(summary = "导入分账账户日志")
    @CommonLog("导入分账账户日志")
    @SaCheckPermission("/biz/sxosafetyaccountrecord/importData")
    @PostMapping("/biz/sxosafetyaccountrecord/importData")
    public CommonResult<JSONObject> importData(@RequestPart("file") MultipartFile file) {
        return CommonResult.data(sxoSafetyAccountRecordService.importData(file));
    }

    /**
     * 导出分账账户日志
     *
     * @author songlc
     * @date  2025/09/16 08:54
     */
    @Operation(summary = "导出分账账户日志")
    @SaCheckPermission("/biz/sxosafetyaccountrecord/exportData")
    @PostMapping(value = "/biz/sxosafetyaccountrecord/exportData", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void exportData(@RequestBody List<SxoSafetyAccountRecordIdParam> sxoSafetyAccountRecordIdParamList, HttpServletResponse response) throws IOException {
        sxoSafetyAccountRecordService.exportData(sxoSafetyAccountRecordIdParamList, response);
    }
}
